//
//  ClassContentCell.m
//  EducationAdminClient
//
//  Created by 孙添凤 on 16/11/7.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "ClassContentCell.h"
#import "UIColor+CL.h"
@implementation ClassContentCell

-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
    if(self){
        
        UIView *v = [self createUI];
        // UIView要加入到self.contentView上 不要加入到self
        [self.contentView addSubview:v];
        UIView *superview = self.contentView;
        UIEdgeInsets edge = UIEdgeInsetsMake(0, 0, 0, 0);
        [v mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(superview).insets(edge);
        }];
        
    }
    return self;
}

-(UIView *)createUI{
    UIView *baseView = [[UIView alloc]init];
    baseView.backgroundColor =[UIColor colorWithHex:0xf4f4f4];
    
    _timeTitle =[[UILabel alloc]init];
    [baseView addSubview:_timeTitle];
    [_timeTitle sizeToFit];
    [_timeTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(baseView.mas_centerX);
        make.top.equalTo(baseView.mas_top);
        make.height.equalTo(@(14));
    }];
    _timeTitle.text = @"2015-12-23";
    _timeTitle.textColor = [UIColor colorWithHex:0x858585];
    _timeTitle.font =[UIFont systemFontOfSize:14];
    
    _timeImg =[[UIImageView alloc]init];
    [baseView addSubview:_timeImg];
    [_timeImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_timeTitle.mas_top).offset(1);
        make.right.equalTo(_timeTitle.mas_left).offset(-7);
        make.height.equalTo(@(12));
        make.width.equalTo(@(12));
    }];
    _timeImg.image =[UIImage imageNamed:@"classroom_time"];
    
   
    
    UIView *v= [[UIView alloc]init];
    [baseView addSubview:v];
    [v mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(baseView.mas_left).offset(10);
        make.right.equalTo(baseView.mas_right).offset(-10);
        make.top.equalTo(baseView.mas_top).offset((28+20)/2);
        make.bottom.equalTo(baseView.mas_bottom).offset(-13);
    }];
    v.backgroundColor =[UIColor whiteColor];
    v.layer.cornerRadius = 4;
    v.layer.borderWidth = 0.5;
    v.layer.borderColor =[[UIColor colorWithHex:0xe7e7e7]CGColor];
    
    
    UIImageView *titleLeft =[[UIImageView alloc]init];
    [v addSubview:titleLeft];
    [titleLeft mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(v.mas_left);
        make.width.equalTo(@(4/2));
        make.height.equalTo(@(16));
        make.top.equalTo(v.mas_top).offset(16);
    }];
    titleLeft.backgroundColor =[UIColor colorWithHex:0xef5152];
    
    UIImageView *line1 =[[UIImageView alloc]init];
    [baseView addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(v.mas_top);
        make.height.equalTo(@(5));
        make.width.equalTo(@(0.5));
        make.centerX.equalTo(v.mas_centerX);
    }];
    line1.backgroundColor =[UIColor colorWithHex:0xc2c2c2];
    
    UIImageView *line2 =[[UIImageView alloc]init];
    [baseView addSubview:line2];
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(v.mas_bottom);
        make.height.equalTo(@(9));
        make.width.equalTo(@(0.5));
        make.centerX.equalTo(v.mas_centerX);
    }];
    line2.backgroundColor =[UIColor colorWithHex:0xc2c2c2];
    
    
    UIView *leftView =[[UIView alloc]init];//图标的背景
    [v addSubview:leftView];
    [leftView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(v.mas_left).offset(15);
        make.top.equalTo(v.mas_top).offset(16);
        make.width.equalTo(@(61));
        make.height.equalTo(@(75));
    }];
    leftView.layer.borderWidth = 0.5;
    leftView.layer.borderColor =[[UIColor colorWithHex:0xe7e7e7]CGColor];
    
    UIImageView *logoImg =[[UIImageView alloc]init];
    [leftView addSubview:logoImg];
    [logoImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(leftView.mas_centerX);
        make.top.equalTo(leftView.mas_top).offset(5);
        make.height.equalTo(@(43));
        make.width.equalTo(@(43));
    }];
    logoImg.image =[UIImage imageNamed:@"icon_classroom"];
    
    
    UILabel *logoName =[[UILabel alloc]init];
    [leftView addSubview:logoName];
    [logoName sizeToFit];
    [logoName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(leftView.mas_centerX);
        make.top.equalTo(logoImg.mas_bottom).offset(7);
    }];
    logoName.text = @"少儿英语";
    logoName.font =[UIFont systemFontOfSize:10];
    logoName.textColor =[UIColor colorWithHex:0x104892];
    //eeeeeeeeee
    _titleName =[[UILabel alloc]init];
    [v addSubview:_titleName];
    [_titleName sizeToFit];
    [_titleName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(leftView.mas_right).offset(13);
        make.top.equalTo(v.mas_top).offset(23);
    }];
    _titleName.font =[UIFont systemFontOfSize:18];
    _titleName.textColor =[UIColor colorWithHex:0x4c4c4c];
    _titleName.text = @"少儿一对一英语基础班";
    
    
    UIImageView *arrow =[[UIImageView alloc]init];
    [v addSubview:arrow];
    [arrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(v.mas_right).offset(-15);
        make.height.equalTo(@(18));
        make.width.equalTo(@(18));
        make.centerY.equalTo(_titleName.mas_centerY);
    }];
    arrow.image =[UIImage imageNamed:@"basics_into"];
    arrow.hidden = YES;//去掉红色小箭头
    _teacher =[[UILabel alloc]init];
    [v addSubview:_teacher];
    [_teacher sizeToFit];
    [_teacher mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(v.mas_left).offset(15);
        make.top.equalTo(leftView.mas_bottom).offset(18);
        make.height.equalTo(@(16));
    }];
    _teacher.textColor =[UIColor colorWithHex:0x4c4c4c];
    _teacher.font =[UIFont systemFontOfSize:16];
    _teacher.text = @"老师姓名";
    
    _teacherName =[[UILabel alloc]init];
    [v addSubview:_teacherName];
    [_teacherName sizeToFit];
    [_teacherName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(v.mas_left).offset(15);
        make.top.equalTo(_teacher.mas_bottom).offset(14);
        make.height.equalTo(@(14));
    }];
    _teacherName.text = @"刘德华";
    _teacherName.font =[UIFont systemFontOfSize:14];
    _teacherName.textColor =[UIColor colorWithHex:0x858585];
    
    _contentTitle =[[UILabel alloc]init];
    [v addSubview:_contentTitle];
    [_contentTitle sizeToFit];
    [_contentTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(v.mas_left).offset(15);
        make.top.equalTo(_teacherName.mas_bottom).offset(14);
        make.height.equalTo(@(16));
    }];
    _contentTitle.textColor =[UIColor colorWithHex:0x4c4c4c];
    _contentTitle.font =[UIFont systemFontOfSize:16];
    _contentTitle.text = @"教学内容";
    
    _content =[[UILabel alloc]init];
    [v addSubview:_content];
    [_content sizeToFit];
    [_content mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(v.mas_left).offset(15);
        make.top.equalTo(_contentTitle.mas_bottom).offset(14);
        make.right.equalTo(v.mas_right).offset(-15);
        make.height.equalTo(@(14));
    }];
    _content.text = @"少儿英语大纲1000单词、口语、阅读";
    _content.font =[UIFont systemFontOfSize:14];
    _content.textColor =[UIColor colorWithHex:0x858585];
    
    UIView *line =[[UIView alloc]init];
    [v addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(v.mas_left).offset(5);
        make.right.equalTo(v.mas_right).offset(-5);
        make.height.equalTo(@(0.5));
        make.top.equalTo(_content.mas_bottom).offset(30);
    }];
    line.backgroundColor =[UIColor colorWithHex:0xe7e7e7];
    
    
    _check =[[UILabel alloc]init];
    [v addSubview:_check];
    [_check sizeToFit];
    [_check mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(v.mas_left).offset(15);
        make.top.equalTo(line.mas_top).offset(13);
        make.height.equalTo(@(14));
    }];
    _check.textColor =[UIColor colorWithHex:0xef5152];
    _check.font =[UIFont systemFontOfSize:14];
    _check.text = @"考勤";
    
    _checkImg =[[UIImageView alloc]init];
    [v addSubview:_checkImg];
    [_checkImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_check.mas_right).offset(9);
        make.bottom.equalTo(_check.mas_bottom);
        make.width.equalTo(@(12));
        make.height.equalTo(@(12));
    }];
    _checkImg.image =[UIImage imageNamed:@"classroom_no"];
    
    _homeWork =[[UILabel alloc]init];
    [v addSubview:_homeWork];
    [_homeWork sizeToFit];
    [_homeWork mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(v.mas_right).offset(-15-12-9);
        make.top.equalTo(line.mas_top).offset(13);
        make.height.equalTo(@(14));
    }];
    _homeWork.textColor =[UIColor colorWithHex:0xef5152];
    _homeWork.font =[UIFont systemFontOfSize:14];
    _homeWork.text = @"课后作业";
    
    _homeWorkImg =[[UIImageView alloc]init];
    [v addSubview:_homeWorkImg];
    [_homeWorkImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_homeWork.mas_right).offset(9);
        make.bottom.equalTo(_homeWork.mas_bottom);
        make.width.equalTo(@(12));
        make.height.equalTo(@(12));
    }];
    _homeWorkImg.image =[UIImage imageNamed:@"classroom_no"];
    
    _check.hidden = YES;
    _checkImg.hidden = YES;
    
    return baseView;
}

-(void)setIsHomework:(BOOL)isHomework{
    if(!isHomework){
        _isHomework =isHomework;
        _homeWork.textColor =[UIColor colorWithHex:0xef5152];
        _homeWorkImg.image =[UIImage imageNamed:@"classroom_no"];
    }else{
        _homeWork.textColor =[UIColor colorWithHex:0x15c871];
        _homeWorkImg.image =[UIImage imageNamed:@"classroom_ok"];
    }
}

-(void)setIsCheck:(BOOL)isCheck{
    if(!isCheck){
        _check.textColor =[UIColor colorWithHex:0xef5152];
        _checkImg.image =[UIImage imageNamed:@"classroom_no"];
    }else{
        _check.textColor =[UIColor colorWithHex:0x15c871];
        _checkImg.image =[UIImage imageNamed:@"classroom_ok"];
    }

}

-(void)setCnName:(NSMutableArray *)cnName{
    _cnName = cnName;
    
    if (_cnName.count>=2){
        _titleName.text = [NSString stringWithFormat:@"%@", [_cnName[1] valueForKey:@"fieldCnName"]];
    }else{
        _titleName.text = @"";
    }
    if (_cnName.count>=3){
        _teacher.text =[NSString stringWithFormat:@"%@",  [_cnName[2] valueForKey:@"fieldCnName"]];
    }else{
        _teacher.text =@"";
    }
    if (_cnName.count>=4){
        _contentTitle.text =[NSString stringWithFormat:@"%@",  [_cnName[3] valueForKey:@"fieldCnName"]];
    }else{
        _contentTitle.text =@"";
    }
    if (_cnName.count>=5){
        _content.text =[NSString stringWithFormat:@"%@",  [_cnName[4] valueForKey:@"fieldCnName"]];
    }else{
        _content.text =@"";
    }
    
    _teacherName.text = @"";
    _content.text =@"";

    _isChangeHomeWork = NO;
    _isHomework = NO;
    
//    for (id IDA in _arrqqqqqqqqqq) {
    for (int i = 0; i<_arrqqqqqqqqqq.count ; i++) {
        id IDA = [_arrqqqqqqqqqq objectAtIndex:i];
        NSString *strA = [NSString stringWithFormat:@"%@", IDA];
        
        if(_cnName.count>=1){
            NSString *testStr = [NSString stringWithFormat:@"%@", [_cnName[0] valueForKey:@"fieldAliasName"]] ;
            NSLog(@"%@",testStr);
            
            if ([testStr isEqualToString:strA]) {
                _timeTitle.text = [NSString stringWithFormat:@"%@", [_dic valueForKey:strA]];
                
                
                //                NSString *dicStr =[_dic objectForKey:@"fieldAliasName"];
                NSString *lastStr = [NSString stringWithFormat:@"DIC_%@",strA];
                
                //&&![_dic valueForKey:strA]
                if([[_dic valueForKey:strA] isKindOfClass:[NSNumber class]]&&![_dic valueForKey:strA]){
                    _timeTitle.text =[NSString stringWithFormat:@"%@", [_dic objectForKey:lastStr]];
                }
                
            }
        }
        if(_cnName.count>=2){
            NSString *testStr = [NSString stringWithFormat:@"%@", [_cnName[1] valueForKey:@"fieldAliasName"]] ;
            NSLog(@"%@",testStr);
            
            if ([testStr isEqualToString:strA]) {
                _titleName.text = [NSString stringWithFormat:@"%@", [_dic valueForKey:strA]];
                
                
                //                NSString *dicStr =[_dic objectForKey:@"fieldAliasName"];
                NSString *lastStr = [NSString stringWithFormat:@"DIC_%@",strA];
                
                //&&![_dic valueForKey:strA]
                if([[_dic valueForKey:strA] isKindOfClass:[NSNumber class]]&&![_dic valueForKey:strA]){
                    _titleName.text =[NSString stringWithFormat:@"%@", [_dic objectForKey:lastStr]];
                }
                
            }
        }
        if(_cnName.count>=3){
            if ([[NSString stringWithFormat:@"%@", [_cnName[2] valueForKey:@"fieldAliasName"]] isEqualToString:strA]) {
                _teacherName.text = [NSString stringWithFormat:@"%@", [_dic valueForKey:strA]];
                
                
                NSString *lastStr = [NSString stringWithFormat:@"DIC_%@",strA];
                
                if([[_dic valueForKey:strA] isKindOfClass:[NSNumber class]]&&![_dic valueForKey:strA]){
                    _teacherName.text =[NSString stringWithFormat:@"%@", [_dic objectForKey:lastStr]];
                    
                    NSLog(@"%@", [_dic objectForKey:lastStr]);
                }
                
            }
        }if(_cnName.count>=4){
            if ([[NSString stringWithFormat:@"%@", [_cnName[3] valueForKey:@"fieldAliasName"]] isEqualToString:strA]) {
                _content.text = [NSString stringWithFormat:@"%@", [_dic valueForKey:strA]];
                
                
                NSString *lastStr = [NSString stringWithFormat:@"DIC_%@",strA];
                
                if([[_dic valueForKey:strA] isKindOfClass:[NSNumber class]]&&![_dic valueForKey:strA]){
                    _content.text =[NSString stringWithFormat:@"%@", [_dic objectForKey:lastStr]];
                    
                    NSLog(@"%@", [_dic objectForKey:lastStr]);
                }
                
            }
        }if(_cnName.count>=5){
            if ([[NSString stringWithFormat:@"%@", [_cnName[4] valueForKey:@"fieldAliasName"]] isEqualToString:strA]) {
                
                NSString *str = [NSString stringWithFormat:@"%@",[_dic valueForKey:strA]];
                if([str isEqualToString:@"已上课"]){
                    self.isCheck = YES;
                }else{
                   self.isCheck = NO;
                }
                
            }
        }if(_cnName.count>=6){
            if ([[NSString stringWithFormat:@"%@", [_cnName[5] valueForKey:@"fieldAliasName"]] isEqualToString:strA]) {
                
                NSString *str =[NSString stringWithFormat:@"%@",[_dic valueForKey:strA]];
                if ([str intValue] >= 1) {
//                    NSString *str =[_dic valueForKey:strA];
                    _isChangeHomeWork = YES;
                    self.isHomework = YES;
            
                }
                
                
            }
        }
//        if(_cnName.count>=4){
//            if ([[NSString stringWithFormat:@"%@", [_cnName[3] valueForKey:@"fieldAliasName"]] isEqualToString:strA]) {
//                _Label3R.text = [NSString stringWithFormat:@"%@", [_dic valueForKey:strA]];
//                
//                //                NSString *dicStr =[_dic objectForKey:@"fieldAliasName"];
//                NSString *lastStr = [NSString stringWithFormat:@"%@",strA];
//                if([[_dic valueForKey:strA] isKindOfClass:[NSNumber class]]&&![_dic valueForKey:strA]){
//                    _Label3R.text =[NSString stringWithFormat:@"%@", [_dic objectForKey:lastStr]];
//                }
//                
//            }
//        }
//        
//        if(_cnName.count>=5){
//            if ([[NSString stringWithFormat:@"%@", [_cnName[4] valueForKey:@"fieldAliasName"]] isEqualToString:strA]) {
//                _Label4R.text = [NSString stringWithFormat:@"%@", [_dic valueForKey:strA]];
//                
//                //                NSString *dicStr =[_dic objectForKey:@"fieldAliasName"];
//                NSString *lastStr = [NSString stringWithFormat:@"%@",strA];
//                if([[_dic valueForKey:strA] isKindOfClass:[NSNumber class]]&&![_dic valueForKey:strA]){
//                    _Label4R.text =[NSString stringWithFormat:@"%@", [_dic objectForKey:lastStr]];
//                }
//                
//            }
//        }
        
    }
    
    for (id IDA in _arrqqqqqqqqqq) {
        NSString *strA = [NSString stringWithFormat:@"%@", IDA];
        if(_cnName.count>=6){
            if ([[NSString stringWithFormat:@"%@", [_cnName[5] valueForKey:@"fieldAliasName"]] isEqualToString:strA]) {
                
                NSString *str =[NSString stringWithFormat:@"%@",[_dic valueForKey:strA]];
                if ([str intValue] >= 1) {
                    //                    NSString *str =[_dic valueForKey:strA];
                    _isChangeHomeWork = YES;
                    self.isHomework = YES;
                    
                }
                
                
            }
        }
    }
        
        if (!_isChangeHomeWork ) {
            _isChangeHomeWork = NO;
        }
    
    if (!_isChangeHomeWork) {
        self.isHomework = NO;
    }
    
    //    _image = [_dic objectForKey:@"AFM_1"];
    //NSString * titleStr = [NSString stringWithFormat:@"%@", [_dic objectForKey:_arrqqqqqqqqqq[0]]];
    
    
    //_titleLabel.text = titleStr;
    
    //NSLog(@"%@", _Label2R.text);
    
    
    
}

-(void)setDic:(NSDictionary *)dic{
    _dic = dic;
    
    NSArray *arrqqqqq = [dic allKeys];
    arrqqqqq = [arrqqqqq sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2){
        NSComparisonResult result = [obj1 compare:obj2];
        return result==NSOrderedDescending;
    }];
    _arrqqqqqqqqqq = arrqqqqq;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
